package com.ycb.controller;

import com.ycb.entity.Goods;
import com.ycb.feign.GoodsClient;
import com.ycb.service.GoodsService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 黄泽群
 * @since 2023-12-11
 */
@RestController
@RequestMapping("/")
@RequiredArgsConstructor
public class GoodsController implements GoodsClient {

    private final GoodsService goodsService;

    @Override
    public Goods getById(Integer id) {
        return goodsService.getById(id);
    }

    @Override
    public Goods subStock(Integer id, Integer num) {
        Goods goods = goodsService.getById(id);
        goods.setStock(goods.getStock() - num);
        goodsService.updateById(goods);
        return goods;
    }
}
